<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>管理系统首页</title>
    <meta name="keywords" content="管理系统首页">
    <meta name="description" content="管理系统首页">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <link rel="stylesheet" href="../static/favicon.ico" th:href="@{favicon.ico}" />
    <link rel="stylesheet" href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" href="../static/css/font-awesome.css" th:href="@{/css/font-awesome.css}" />
    <link rel="stylesheet" href="../static/css/animate.css" th:href="@{/css/animate.css}" />
    <link rel="stylesheet" href="../static/css/style.css" th:href="@{/css/style.css}" />
    <link rel="stylesheet" href="../static/ruoyi/css/ry-ui.css" th:href="@{/ruoyi/css/ry-ui.min.css?v=2.1.0}" />
    <link rel="stylesheet" href="../static/ruoyi/css/index.css" th:href="@{/ruoyi/css/index.css?v=2.1.0}" />
		<style type="text/css">
        .nav > li:hover .dropdown-menu {
            display: block;
        }
    </style>
</head>
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow: hidden"
      th:classappend="${@configService.selectConfigByKey('sys.index.skinName')}">
<div id="wrapper">

    <!--左侧导航开始-->
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="nav-close">
            <i class="fa fa-times-circle"></i>
        </div>
        <div class="sidebar-collapse">
            <ul class="nav" id="side-menu">
                <li class="nav-header">
                    <div class="dropdown profile-element"> <span>
                         <img src="../static/img/profile.jpg" th:src="(${sysUser.avatar} == '') ? '/img/profile.jpg' : '/profile/' + ${sysUser.avatar}"
                              alt="image" class="img-circle" height="60" width="60"/></span>
                        <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                          <span class="clear"><span class="block m-t-xs"><strong class="font-bold" th:text="${sysUser.userName}">用户</strong></span>
                         <span class="text-muted text-xs block"><span th:text="${sysUser.dept.deptName}">部门</span> <b class="caret"></b></span> </span> </a>
                        <ul class="dropdown-menu animated fadeInRight m-t-xs">
                            <li><a class="menuItem" th:href="@{/system/sysUser/profile}">个人信息</a></li>
                            <li class="divider"></li>
                            <li><a th:href="@{logout}">退出</a></li>
                        </ul>
                    </div>
                </li>
                <li>
                    <a href="/system/main" class="menuItem">
                        <i class="fa fa-home"></i>
                        <span class="nav-label">首页</span>
                    </a>
                </li>
                <li th:each="menu : ${menus}">
                    <a th:if="${#lists.isEmpty(menu.children)}" class="menuItem" th:href="@{${menu.url}}">
                        <i class="fa fa fa-bar-chart-o" th:class="${menu.icon}"></i>
                        <span class="nav-label" th:text="${menu.menuName}">一级菜单</span>
                    </a>
                    <a th:if="${not #lists.isEmpty(menu.children)}" href="#">
                        <i class="fa fa fa-bar-chart-o" th:class="${menu.icon}"></i>
                        <span class="nav-label" th:text="${menu.menuName}">一级菜单</span>
                        <span class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level collapse">
                        <li th:each="cmenu : ${menu.children}">
                            <a th:if="${#lists.isEmpty(cmenu.children)}" class="menuItem" th:href="@{${cmenu.url}}">
                                <span th:utext="${cmenu.menuName}">二级菜单</span>
                            </a>
                            <a th:if="${not #lists.isEmpty(cmenu.children)}" href="#">
                                <span th:utext="${cmenu.menuName}">二级菜单</span>
                                <span class="fa arrow"></span>
                            </a>
                            <ul th:if="${not #lists.isEmpty(cmenu.children)}" class="nav nav-third-level">
                                <li th:each="emenu : ${cmenu.children}">
                                    <a class="menuItem" th:href="@{${emenu.url}}">
                                        <span th:text="${emenu.menuName}">三级菜单</span>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </nav>
    <!--左侧导航结束-->

    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation"
                 style="margin-bottom: 0">
                <div class="navbar-header">
                    <a class="navbar-minimalize minimalize-styl-2 btn btn-default " href="#" title="收起菜单">
                        <i class="fa fa-bars"></i>
                    </a>
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li>
                        <span class="m-r-sm text-muted welcome-message">欢迎进入管理后台.</span>
                    </li>
                    <li id="msgId" class="dropdown" style="display: none;position: fixed;z-index: 9000;top:80%;left:90%;">
                        <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#">
                            <span id="msgCount" class="label label-primary" style="width: 150px;height: 60px;font-size:20px;">0条消息待处理</span>
                        </a>
                    </li>
                    <!--<li><a href="/agent/exchange/add" class="menuItem"><i class="fa fa-sign-out"></i>提现</a></li>-->
                    <li><a id="fullScreen"><i class="fa fa-arrows-alt"></i>全屏</a></li>
                    <li><a th:href="@{logout}"><i class="fa fa-sign-out"></i>退出</a></li>
                </ul>
            </nav>
        </div>
        <div class="row content-tabs">
            <button class="roll-nav roll-left tabLeft">
                <i class="fa fa-backward"></i>
            </button>
            <nav class="page-tabs menuTabs">
                <div class="page-tabs-content">
                    <a href="javascript:;" class="active menuTab" data-id="/system/main">首页</a>
                </div>
            </nav>
            <button class="roll-nav roll-right tabRight">
                <i class="fa fa-forward"></i>
            </button>
            <div class="btn-group roll-nav roll-right">
                <button class="dropdown J_tabClose" data-toggle="dropdown">
                    页签操作<span class="caret"></span>
                </button>
                <ul role="menu" class="dropdown-menu dropdown-menu-right">
                    <li><a class="tabCloseCurrent" href="javascript:void(0);">关闭当前</a></li>
                    <li><a class="tabCloseOther" href="javascript:void(0);">关闭其他</a></li>
                    <li><a class="tabCloseAll" href="javascript:void(0);">全部关闭</a></li>
                </ul>
            </div>
            <a href="#" class="roll-nav roll-right tabReload"><i class="fa fa-refresh"></i> 刷新</a>
        </div>
        <div class="row mainContent" id="content-main">
            <iframe class="RuoYi_iframe" name="iframe0" width="100%" height="100%" data-id="/system/main" th:src="@{/system/main}" frameborder="0" seamless></iframe>
        </div>
        <div class="footer">
            <div class="pull-right" th:text="'© '+${copyrightYear}+' YL Copyright'">© 2018 YL Copyright</div>
        </div>

        <div id="chatBox" class="talk_con" style="position: fixed;z-index: 5000; top:20%;left:40%;background-color:white;display: none;">
            <div class="form-group" style="margin-top:20px;">
                <label class="col-sm-10 control-label"><h3 id="player-nickname"> </h3></label>
                <input type="hidden" id="player-userId" value="">
                <button onclick="closeChatBox()" class="btn btn-danger" type="button">关闭</button>
            </div>
            <div class="talk_show" id="words"></div>
            <div class="talk_input">
                <div class="form-group">
                    <div class="col-sm-10" style="height:35px;">
                        <select id="select" class="form-control m-b"  onchange="$('#answer').val($('#select option:selected').text())">

                        </select>
                        <input class="" type="text" id="answer"
                               style="position:relative;width:95%;height:30px;border:0px;padding-left:18px;top:-47px;left:1px;"/>
                    </div>
                    <button onclick="sendMsg()" class="btn btn-primary">确认修改</button>
                </div>
            </div>
        </div>

        <div id="options" style="position: fixed; overflow:scroll; z-index: 9100; height: 250px; width: 220px; top:
        60%; left: 75%; background-color:white;border: 2px solid black;display: none;">
            <div style="text-align:right;"><button class="btn btn-danger" onclick="closeOptions()" type="button">关闭</button></div>
            <ul id="options-ul" class="dropdown dropdown-alerts">

            </ul>
        </div>

    </div>
    <!--右侧部分结束-->
</div>
<!-- 全局js -->
<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script src="../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>
<script src="../static/js/plugins/metisMenu/jquery.metisMenu.js" th:src="@{/js/plugins/metisMenu/jquery.metisMenu.js}"></script>
<script src="../static/js/plugins/slimscroll/jquery.slimscroll.min.js" th:src="@{/js/plugins/slimscroll/jquery.slimscroll.min.js}"></script>
<script src="../static/ajax/libs/blockUI/jquery.blockUI.js" th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
<script src="../static/ajax/libs/layer/layer.min.js" th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script src="../static/ajax/libs/fullscreen/jquery.fullscreen.js" th:src="@{/ajax/libs/fullscreen/jquery.fullscreen.js}"></script>
<script src="../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui.js?v=2.1.0}"></script>
<script src="../static/ruoyi/index.min.js" th:src="@{/ruoyi/index.min.js?v=2.1.0}"></script>
<script th:inline="javascript">
    var msgFlag = [[${@permissionService.hasPermi('system:msg:view')}]];
    if (msgFlag === '') {
        $("#msgId").show();
        var selectMsgConfig = {
            url: "/system/msgList",
            type: "get",
            dataType: "json",
            data: {},
            success: function (result) {
                if (result.code === 0) {
                    $("#msgCount").html(result.msgCount+"条消息待处理");
                    // $("#agentlogCount").html(result.agentlogCount);
                    // $("#feedbacklogCount").html(result.feedbacklogCount);
                } else {
                    if (result.msg === '未登录或登录超时。请重新登录') {
                        //去掉定时器的方法
                        window.clearInterval(t1);
                    } else {
                        console.log(result.msg)
                    }
                }
            },
            error: function () {
                //去掉定时器的方法
                window.clearInterval(t1);
            }
        };

        function selectMsg() {
            $.ajax(selectMsgConfig);
        }

        var t1 = window.setInterval(selectMsg, 5000);
    }

    $("#msgId").click(function () {
        $("#options-ul").html('');

        var msgList = {
            url: "/system/msgList",
            type:"get",
            dataType: "json",
            data: {},
            success: function (result) {
                if (result.code == 0) {

                    $("#msgCount").html(result.msgCount+"条消息待处理");
                    //-----------------------------------------------
                    //----------- 循环展现代理申请
                    for(var key in result.agentLogs){
                        var value = result.agentLogs[key];
                        var agentId = value.split(",")[0];
                        var userId = value.split(",")[1];
                        var content = '<li>\n' +
                            '<a href="javascript:;" onclick="javascript:goEditAgentlog(\''+ agentId +'\')" class="menuItem">' +
                            '<div>' +
                            '<i class="fa fa-envelope fa-fw"></i> <span>玩家'+ userId +'：代理申请</span>' +
                            '</div>' +
                            '</a>' +
                            '</li>' +
                            '<li class="divider"></li>';
                        $("#options-ul").html( $("#options-ul").html() + content );
                    }
                    //-----------------------------------------------
                    //----------- 循环展现提现信息
                    for(var key in result.playerExchanges){
                        var value = result.playerExchanges[key];
                        var playerExchangeId = value.split(",")[0];
                        var userId = value.split(",")[1];
                        var content = '<li>\n' +
                            '<a href="javascript:;" onclick="javascript:goPlayerExchangelog(\''+ playerExchangeId +'\')" class="menuItem">' +
                            '<div>' +
                            '<i class="fa fa-envelope fa-fw"></i> <span>玩家'+ userId +'：提现信息</span>' +
                            '</div>' +
                            '</a>' +
                            '</li>' +
                            '<li class="divider"></li>';
                        $("#options-ul").html( $("#options-ul").html() + content );
                    }
                    //-----------------------------------------------
                    //----------- 循环展现提现信息
                    for(var key in result.agentExchangeInfos){
                        var value = result.agentExchangeInfos[key];
                        var agentExchangeId = value.split(",")[0];
                        var userId = value.split(",")[1];
                        var content = '<li>\n' +
                            '<a href="javascript:;" onclick="javascript:goAgentExchangelog(\''+ agentExchangeId +'\')" class="menuItem">' +
                            '<div>' +
                            '<i class="fa fa-envelope fa-fw"></i> <span>代理'+ userId +'：提现信息</span>' +
                            '</div>' +
                            '</a>' +
                            '</li>' +
                            '<li class="divider"></li>';
                        $("#options-ul").html( $("#options-ul").html() + content );
                    }

                    //-----------------------------------------------
                    //----------- 循环展现玩家留言
                    console.log(result.feedbackProblemLogs);
                    for(var key in result.feedbackProblemLogs){
                        var userId = result.feedbackProblemLogs[key];
                        var content = '<li>\n' +
                            '<a href="javascript:;" onclick="javascript:goEditFeedback(\''+ userId +'\')" class="menuItem">' +
                            '<div>' +
                            '<i class="fa fa-envelope fa-fw"></i> <span>玩家'+ userId +'：留言</span>' +
                            '</div>' +
                            '</a>' +
                            '</li>' +
                            '<li class="divider"></li>';
                        $("#options-ul").html( $("#options-ul").html() + content );
                    }
                }
            },
            error: function () {
                alert("");
            }
        };

        $.ajax(msgList);
        $("#options").css("display", "block");
    });

    function goEditFeedback(userId) {
        var feedback = {
            url: "msg/feedbacklog/queryFeedBack",
            type:"post",
            dataType: "json",
            data: {
                userId: userId
            },
            success: function (result) {
                if(result.code === 0){
                    $("#player-nickname").html(result.player.nickName + ' (userId: '+ result.player.userId +' ):');
                    $("#player-userId").val(result.player.userId);
                    $("#words").html(result.feedBackLog);
                    $("#chatBox").css("display", "block");
                    $("#options").css("display", "none");

                    var option = '';
                    for (var i = 0; i < result.quickReply.length; i++) {
                        option = option + '<option  value="'+ result.quickReply[i].replyContext +'">'+ result.quickReply[i].replyContext +'</option>';
                    }
                    $("#select").html( option );
                }
            },
            error: function () {
                alert("");
            }
        }
        $.ajax(feedback);
    }

    function sendMsg(){
        //定义空字符串
        var str = $("#answer").val();
        if(str === ""){
            alert("消息不能为空");
            return;
        }

        var msg = {
            url: "msg/feedbacklog/saveFeedBack",
            type:"post",
            dataType: "json",
            data: {
                userId: $("#player-userId").val(),
                content: str
            },
            success: function (result) {
                if(result.code === 0){
                    str = '<div class="atalk"><span>客服 :' + $("#talkwords").val() +'</span></div>';
                    $("#words").html( $("#words").html() + result.content );
                    $("#answer").val('');
                }
            },
            error: function () {
                alert('操作失败');
            }
        }
        $.ajax(msg);
    }

    function closeChatBox() {
        $("#chatBox").css("display", "none");
        $("#words").html('');
    }

    function closeOptions() {
        $("#options").css("display", "none");

    }

    var options = {
        goEditAgentUrl: "agent/info/add",
        goPlayerExchange: "player/exchange/edit/{id}",
        goAgentExchange: "agent/exchange/edit/{id}",
    };

    /**
     * 跳转 代理申请页面
     *
     * @param id
     */
    function goEditAgentlog(id) {
        $("#options").css("display", "none");
        var goAdd = {
            url: "msg/agentlog/queryOne",
            type:"post",
            dataType: "json",
            data: {
                id: id
            },
            success: function (result) {
                if(result.code === 0){
                    var url = options.goEditAgentUrl + "?phoneNo="+ result.agentLog.mobileNo +"&wechatNo="+result.agentLog.weChatNo+"&id="+id; //.replace("{id}", id)
                    $.modal.open("打开代理申请窗口", url, $(window).width()-200, $(window).height()-100);
                }else {
                    alert('操作失败');
                }
            },
            error: function () {
                alert('操作失败');
            }
        }

        $.ajax(goAdd);
    }

    /**
     * 跳转 提现页面
     *
     * @param id
     */
    function goPlayerExchangelog(id) {
        $("#options").css("display", "none");
        var url = options.goPlayerExchange.replace("{id}", id);
        $.modal.open("打开提现窗口", url, $(window).width()-400, $(window).height()-200);
    }

    /**
     * 跳转 提现页面
     *
     * @param id
     */
    function goAgentExchangelog(id) {
        $("#options").css("display", "none");
        var url = options.goAgentExchange.replace("{id}", id);
        $.modal.open("打开提现窗口", url, $(window).width()-400, $(window).height()-200);
    }
</script>
</body>
</html>
